using UnityEditor;
using UnityEngine;

namespace DL.UI
{
    //提示窗口
    public class TipsMgr : Singleton<TipsMgr>
    {
        public TextData _prefab;
        public TextData _tipsData;
        protected override void Construct()
        {
            if (_prefab == null)
            {
                _prefab = Load.Inst.LoadUIPage("TipsPage").GetComponent<TextData>();
            }
        }

        public TextData TipsData
        {
            get
            {
                if (_tipsData == null)
                {
                    _tipsData = Instantiate(_prefab, TipsParent.transform).GetComponent<TextData>();
                    _tipsData.name = _prefab.name;
                }

                return _tipsData;
            }

        }

        private GameObject _tipsParent;
        public GameObject TipsParent
        {
            get
            {
                if (_tipsParent == null)
                {
                    
                    _tipsParent = GameObject.Find("TipParent");
                    if (_tipsParent == null)
                    {
                        Debug.LogError("未找到TipsParent节点,请检查！！！");
                    }
                }
                return _tipsParent;
            }
        }

        public void Create(string text, params object[] args)
        {
            Color color;
            if (args.Length == 0)
            {
                color = Color.white;
            }
            else
            {
                color = (Color)args[0];
            }

            Create(text, color);
        }

        public void Create(string text, Color color)
        {
            TipsData.ReStart(text,color);
        }
        
        public void Create(string text)
        {
            Create(text, Color.white);
        }
#if UNITY_EDITOR
        [MenuItem("测试单元/界面测试/启动Tips")]
        public static void TipsCreate()
        {
            // TipsMgr.Inst.Create("这是一条测试信息");
            TipsMgr.Inst.Create("这是一条带颜色的测试信息", Color.magenta);
        }
#endif
    }
}
